home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE19 / SURVIVE / USERAPI.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1997-01-19  |  2.2 KB  |  88 lines

  1. unit UserAPI;
  2.  
  3. interface
  4.  
  5. uses
  6.   DB;
  7.  
  8. procedure AddDBUser(DB: TDatabase;
  9.                     UserName,
  10.                     Password,
  11.                     FirstName,
  12.                     LastName: string;
  13.                     MustChangePassword: Boolean;
  14.                     PasswordLifespan: Integer);
  15.  
  16. procedure EditDBUser(DB: TDatabase;
  17.                      UserName,
  18.                      Password,
  19.                      FirstName,
  20.                      LastName: string;
  21.                      MustChangePassword: Boolean;
  22.                      PasswordLifespan: Integer);
  23.  
  24. implementation
  25.  
  26. uses
  27.   SysUtils, DBTables, FmMain;
  28.  
  29. function DelimitedStr(S: string): string;
  30. begin
  31.   Result := '''' + S + '''';
  32. end;
  33.  
  34. function BoolToChar(B: Boolean): Char;
  35. begin
  36.   if B then Result := 'Y' else Result := 'N';
  37. end;
  38.  
  39. procedure AddDBUser(DB: TDatabase;
  40.                     Username,
  41.                     Password,
  42.                     FirstName,
  43.                     LastName: string;
  44.                     MustChangePassword: Boolean;
  45.                     PasswordLifespan: Integer);
  46. begin
  47.   with TQuery.Create(nil) do
  48.   try
  49.     DatabaseName := DB.DatabaseName;
  50.     SQL.Add('execute AddUser ');
  51.     SQL.Add(DelimitedStr(Username) + ',');
  52.     SQL.Add(DelimitedStr(Password) + ',');
  53.     SQL.Add(DelimitedStr(FirstName) + ',');
  54.     SQL.Add(DelimitedStr(LastName) +',');
  55.     SQL.Add(IntToStr(PasswordLifespan) + ',');
  56.     SQL.Add(BoolToChar(MustChangePassword));
  57.     ExecSQL;
  58.   finally
  59.     Free;
  60.   end;
  61. end;
  62.  
  63. procedure EditDBUser(DB: TDatabase;
  64.                      Username,
  65.                      Password,
  66.                      FirstName,
  67.                      LastName: string;
  68.                      MustChangePassword: Boolean;
  69.                      PasswordLifespan: Integer);
  70. begin
  71.   with TQuery.Create(nil) do
  72.   try
  73.     DatabaseName := DB.DatabaseName;
  74.     SQL.Add('execute EditUser ');
  75.     SQL.Add(DelimitedStr(Username) + ',');
  76.     SQL.Add(DelimitedStr(Trim(Password)) + ',');
  77.     SQL.Add(DelimitedStr(FirstName) + ',');
  78.     SQL.Add(DelimitedStr(LastName) +',');
  79.     SQL.Add(IntToStr(PasswordLifespan) + ',');
  80.     SQL.Add(BoolToChar(MustChangePassword));
  81.     ExecSQL;
  82.   finally
  83.     Free;
  84.   end;
  85. end;
  86.  
  87. end.
  88.